package cn.krund.lyc.hotlerobot.utils;

import java.util.Arrays;
import java.util.Map;

/**
 * @包名: cn.krund.lyc.hotlerobot.utils
 * @作者: 刘育成
 * @时间: 2018/4/5  15:02
 * @org: 克路德人工智能
 * @描述: TODO
 * @fileName: Sign
 */

public class Sign {

    public static String getSign(Map<String,String> paramMap,String secret){

        String[] keyArray = paramMap.keySet().toArray(new String[0]);
        Arrays.sort(keyArray);

        // 拼接有序的参数名-值串
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(secret);
        for (String key : keyArray) {
            stringBuilder.append(key).append(paramMap.get(key));
        }

        stringBuilder.append(secret);

        String codes = stringBuilder.toString();

        String sign = MD5Util.MD5(codes).toUpperCase();
        return sign;
    }
}
